package bid.yanhj.common.service;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import bid.yanhj.common.model.ResultBody;
import bid.yanhj.common.model.ResultError;
import bid.yanhj.common.service.FormatService.LOGSTEP;
import bid.yanhj.common.util.Constants;

/**
 * 请求返回对象工具类.
 * @author yanhaijiang
 *
 */
public final class ResultService {
    /**
     * Constructor.
     */
    private ResultService() {

    }
    /**
     * create success result.
     * 
     * @param data Object
     * @return Object
     */
    public static Object success(Object data) {
    	Object resultObject = new ResultBody(Constants.ResultCode.SUCCESS, data);
        CacheService.putResult(resultObject);
        FormatService.accMark(LOGSTEP.SUCCESS);
        return new ResponseEntity<Object>(resultObject, HttpStatus.OK);
    }

    /**
     * create error result.
     * 
     * @return Object
     */
    public static Object unknownError() {
        Object resultObject =
                new ResultError(Constants.ResultCode.ERR_UNKOWN,
                        Constants.ResultCode.ERR_MSG[Constants.ResultCode.ERR_UNKOWN]);
        CacheService.putResult(resultObject);
        FormatService.accMark(LOGSTEP.FAILED);
        return resultObject;
    }
}
